import {NavigationContainer, Theme} from '@react-navigation/native';
import UpViewParent from 'M/UI/Components/UpViewParent';
import ToastComponent from 'M/UI/Libraries/Toast';
import React, {useEffect, useState} from 'react';
import Style from 'M/UI/Style';
import {globalService} from 'M/Services';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import Remotes from 'WE/index';

const Stack = createNativeStackNavigator();

export default function App(): JSX.Element {
  const [theme, setTheme] = useState<Theme>(Style.theme);
  const [remote] = useState<Array<any>>(Remotes);
  useEffect(() => {
    Style.addThemeChangeListener(setTheme);
    const subscription = globalService.addLinkingEventListener();
    return () => subscription.remove();
  }, []);
  return (
    <NavigationContainer theme={theme}>
      <Stack.Navigator initialRouteName="Home">
        {remote.map(value => (
          <Stack.Screen key={value.name} {...value} />
        ))}
      </Stack.Navigator>
      <UpViewParent />
      <ToastComponent />
    </NavigationContainer>
  );
}
